package pkg.networking;

/**
 * BomberBoy, CPS240 Term Project - Team A
 * Andrew Osterink, David Bash, Scott Kidder
 * 
 * Wraps all commands sent over network. There can also be attached
 * meta data via object and flags. Its not required to have an internal command
 * so it might be null.
 */

import pkg.commands.*;

import java.io.Serializable;

public class RemoteCommand implements ICommand,Serializable {

	private static final long serialVersionUID = -5579401633261331697L;
	private ICommand internalCommand;
	private Object obj = null;
	private int userId;
	private int flag;
	
	public RemoteCommand(ICommand cmd,int userID)
	{
		this.internalCommand = cmd;
		flag = Flags.None;
		this.userId = userID;
	}
	
	public RemoteCommand(Object obj,int userID)
	{
		this.obj = obj;
		this.userId = userID;
	}
	
	
	@Override
	public void execute() {
		// TODO Auto-generated method stub
	}
	
	public ICommand getInternalCommand()
	{
		return (ICommand)internalCommand;
	}
	
	public Object getObject()
	{
		return obj;
	}
	
	public int getUserId()
	{
		return userId;
	}
	
	public int getFlags()
	{
		return flag;
	}
	
	public void setFlags(int flag)
	{
		this.flag = flag;
	}
	
	public void setObject(Object obj)
	{
		System.exit(0);
		this.obj = obj;
	}
	
	public static ICommand unpack(ICommand command)
	{
		if(isRemoteCommand(command))
			return ((RemoteCommand)command).getInternalCommand();
		return command;
	}
	
	public static boolean isRemoteCommand(ICommand command)
	{
		return command instanceof RemoteCommand;
	}
	
	static class Flags
	{
		public static final int None = 1;
	    public static final	int Verrify = 2;
	    public static final int PlayerJoin = 4;
	    public static final int SynchPositions = 8;
	}

}
